fix(billing): post-#705 follow-ups — backfill + cleanup#708
Conversation
Production blocker: orgs created BEFORE 20260506132900 never got their
`grida_billing.account` and free `grida_billing.subscription` rows. The
provisioning trigger only fires on `AFTER INSERT`, so existing orgs were
left empty. First checkout for those orgs crashed with:
Error: resolveOrCreateStripeCustomer attach: billing account not
provisioned for organization 255
Single-shot data fix: iterate `public.organization` and call
`fn_provision_account` for each (idempotent — INSERT … ON CONFLICT DO
NOTHING). The guard in `fn_attach_stripe_customer` stays loud — once
the data is correct, that RAISE is the right behavior for any future
anomaly (deleted row, bypassed trigger, partial restore). Self-heal in
the guard's path would silence real signal.
The string "Test mode: use card 4242 4242 4242 4242…" was an unguarded footer on the plan cards — visible in production. The test card number belongs in docs/contributing/billing.md (where it already lives), not in the customer-facing UI. Other test-mode UI is properly gated behind state.is_test_mode (the sandbox disclaimer at the bottom of /billing); this string was the lone unguarded one.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughAdds a one-time DB migration that provisions billing for all existing organizations and removes the "Test mode" informational paragraph from the billing upgrade UI. ChangesBilling Account Provisioning
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 Microsoft Presidio Analyzer (2.2.362)supabase/migrations/20260507000000_grida_billing_backfill_provision.sqlMicrosoft Presidio Analyzer failed to scan this file Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Follow-up to #705 (now merged). Two distinct fixes:
1. Production hot-fix: backfill billing rows for pre-migration orgs
#705's
20260506132900_grida_billing.sqladds anAFTER INSERTtriggerthat calls
fn_provision_accountto create thegrida_billing.accountand freegrida_billing.subscriptionrows fornew organizations. The trigger only fires on new orgs — pre-existing
ones never got their billing rows.
This blocked first checkout for any pre-migration org with:
Single-shot data fix in
20260507000000_grida_billing_backfill_provision.sql:iterate
public.organizationand callfn_provision_accountfor each.Idempotent —
fn_provision_accountusesINSERT … ON CONFLICT DO NOTHING.The guard in
fn_attach_stripe_customerstays loud — once the data iscorrect, that
RAISEis the right behavior for any future anomaly(deleted row, bypassed trigger, partial restore). Adding self-heal in
the guard's path would silence real signal.
2. UX polish: drop dev test-card hint from upgrade page
Test mode: use card 4242 4242 4242 4242…was an unguarded footer on theplan cards — visible in production. The test card number belongs in
docs/contributing/billing.md(where it already lives), not in the customer-facing UI. Other test-mode
copy (the "sandbox" disclaimer at the bottom of /billing) is correctly
gated behind
state.is_test_mode— this string was the lone unguarded one.Test plan
supabase db push/organizations/<org>/settings/billing/upgradeis_test_mode) still appears in dev / staging whereBILLING_TEST_MODE=trueRelated
Summary by CodeRabbit
Bug Fixes
Chores